import 'package:bxultimate/data/request/organization_request.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';

import 'state.dart';

class OrganizationAttendanceListController extends GetxController {
  final OrganizationAttendanceListState state = OrganizationAttendanceListState();

  var pageSize = 10;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();

    getData(false);
  }

  getData(bool isClear) async {
    var list = await OrganizationRequest.getCreateAttendanceClockingPageList(state.page, pageSize);
    if(isClear){
      state.dataList = list;
    }else{
      state.dataList.addAll(list);
    }
  }

  Future<void> onRefresh() async {
    state.page = 1;
    await getData(true);
  }

  Future<void> onLoad() async {
    state.page++;
    await getData(false);
  }

  void removeByIndex(index) async{
    await OrganizationRequest.deleteAttendanceClocking(state.dataList[index].id);
    SmartDialog.showNotify(msg: '删除成功', notifyType: NotifyType.success);
    await onRefresh();
  }
}
